/*
 * @title: 路由配置
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-21 17:01:07
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-05-01 22:14:00
 * @version: 1.0.3
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
 */
import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/layout/index';

Vue.use(Router);

export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    meta: { title: '登录', noCache: true },
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    name: 'Page404',
    component: () => import('@/views/features/404'),
    hidden: true
  },
  {
    path: '/401',
    name: 'Page401',
    component: () => import('@/views/features/401'),
    hidden: true
  },
  {
    path: '/redirect',
    name: 'Redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        name: 'Redirect2',
        component: () => import('@/views/features/redirect')
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    name: 'Layout',
    redirect: '/dashboard',
    children: [
      {
        name: 'Dashboard',
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        hidden: true,
        meta: { title: '首页', picon: 'ht-icon-shouye', affix: true, noCache: false }
      }
      // 动态菜单添加在dashboard嵌套子路由下
      // ...
    ]
  }

];
// 动态需要根据权限加载的路由 该方式将路由配置在前端来进行权限校验
// export const asyncRoutes = [
//   {
//     path: '/permission',
//     component: Layout,
//     redirect: '/permission/page',
//     alwaysShow: true, // will always show the root menu
//     name: 'Permission',
//     meta: {
//       title: 'permission',
//       icon: 'lock',
//       roles: ['admin', 'editor'] // you can set roles in root nav
//     }}
// ];
const createRouter = () => new Router({
  mode: 'history', // 如果是mock js模拟后端，使用hash
  // mode: 'hash',
  base: '/', // 上下文
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});
const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}

export default router;
